package com.gxuwz.Market.business.action.web;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;
import java.util.Random;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import com.gxuwz.Market.business.entity.ServiceAcademy;
import com.gxuwz.Market.business.entity.ServiceRecord;
import com.gxuwz.Market.business.entity.ServiceMajor;
import com.gxuwz.Market.business.service.IServiceAcademyService;
import com.gxuwz.Market.business.service.IServiceRecordService;
import com.gxuwz.Market.business.service.IServiceMajorService;
import com.gxuwz.core.pagination.Result;
import com.gxuwz.core.web.action.BaseAction;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;

public class ServiceRecordAction extends BaseAction implements Preparable, ModelDriven<ServiceRecord> {

	protected static final String LIST_JSP = "/WEB-INF/page/web/ServiceRecord_list.jsp";  
	protected static final String ADD_JSP = "/WEB-INF/page/web/ServiceRecord_add.jsp";
	protected static final String EDIT_JSP = "/WEB-INF/page/web/ServiceRecord_edit.jsp";
	
	@Autowired
	private IServiceRecordService serviceRecordService;
	@Autowired
	private IServiceMajorService serviceMajorService;
	
	
	private ServiceRecord serviceRecord;
	private Result<ServiceRecord> pageResult;
	private List<ServiceMajor> majorList;
	
	
	
	

	@Override
	public void prepare() throws Exception {
		if(null == serviceRecord){
			serviceRecord = new ServiceRecord();
		}
	}

	@Override
	public ServiceRecord getModel() {
		return serviceRecord;
	}
	
	@Override
	public String execute() throws Exception {
		
		return SUCCESS;
	}
	
	/**
	 * 打开列表页面
	 * @return
	 */
	public String openList(){
		String writerId = (String)getRequest().getSession().getAttribute("userId");
		serviceRecord.setWriterId(writerId);
		pageResult = serviceRecordService.find(serviceRecord, getPage(), getRow());
		setForwardView(LIST_JSP);
		return SUCCESS;
	}


	/**
	 * 打开修改页面
	 * @return
	 */
	public String openEdit(){
		setForwardView(EDIT_JSP);
		return SUCCESS;
	}

	public String openAdd() {
		majorList = serviceMajorService.findAll();
		
		
		
		setForwardView(ADD_JSP);
		return SUCCESS;
	}
	
	
	
	public String edit(){
		serviceRecordService.update(serviceRecord);
		return openList();
	}
	
	public ServiceRecord getServiceRecord() {
		return serviceRecord;
	}

	public void setServiceRecord(ServiceRecord serviceRecord) {
		this.serviceRecord = serviceRecord;
	}

	public Result<ServiceRecord> getPageResult() {
		return pageResult;
	}

	public void setPageResult(Result<ServiceRecord> pageResult) {
		this.pageResult = pageResult;
	}

	



	public List<ServiceMajor> getMajorList() {
		return majorList;
	}

	public void setMajorList(List<ServiceMajor> majorList) {
		this.majorList = majorList;
	}



	
	
	
}
